/**
 * Created by dev-001 on 2017/2/27.
 * 考试
 */
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;

const ExamSchema = new Schema({
    name: String,
    teacher: {
        type: ObjectId,
        ref: 'User'
    }, //具体考试的创建者
    subject: {
        type: ObjectId,
        ref: 'Subject'
    }, //科目
    status: String,  //状态，基本信息，上传试卷，划区域，完成，考试完成等
    paperType: {
        type: ObjectId,
        ref: 'PaperType'
    }, //纸张类型
    date: Date, // 考试日期
    examType: {
        type: ObjectId,
        ref: 'ExamType'
    }, // 月考，周考等
    groupId: {
        type: ObjectId,
        ref: 'Exam'
    },//题组的id
    school: {
        type: ObjectId,
        ref: 'School'
    },
    grade: {
        type: ObjectId,
        ref: 'Grade'
    },
    clazzs: [{
        type: ObjectId,
        ref: 'Clazz'
    }],
    paperCount: Number,
    attachment: {
        type: ObjectId,
        ref: 'Attachment'
    },
    originAttachment: {
        type: ObjectId,
        ref: 'Attachment'
    },
    scope: Number,//3年级，1单级，2多级
    type: Number,//1理科，2文科，3艺体, 4通用
    createdAt: Date,
    updatedAt: Date
});

ExamSchema.pre('save', function (next) {
    this.createdAt = new Date();
    this.updatedAt = new Date();
    next();
});

ExamSchema.pre('update', function (next) {
    this.updatedAt = new Date();
    next();
});

export default mongoose.model('Exam', ExamSchema);